<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/cms/theme/include/taglib.jsp" %>
<html>
<head>
    <title>${site.name}&&${category.name}</title>
    <%@ include file="head.jsp" %>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/3rd-lib/wangEditor/css/wangEditor.min.css">
    <link rel="stylesheet" href="${ctxStatic}/faq/css/faq.css"/>
</head>
<body>
<%@ include file="header.jsp" %>
<div class="am-container">
    <div class="content" id="content">
        <!-- 模块排版 -->
        <div class="am-g">
            <div class="am-u-sm-8" style="padding: 0px;padding-right: 1.1em;">
                <div class="am-panel am-panel-default">
                    <div class="title"><span>我要提问</span></div>
                    <div class="am-panel-bd">
                        <c:if test="${not empty user}">
                        <form id="questions" class="am-form am-form-horizontal" action="${ctx}/faq/questions/submit" data-am-validator method="post">
                            <input type="hidden" name="device" value="${empty device?'web':device}"/>
                            <div class="am-form-group">
                                <label class="am-form-label">问题标题:</label>
                                <div>
                                    <input type="text" id="title" name="title" required />
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-form-label">问题内容（请将问题描述清楚）：</label>
                                <div><textarea id="contentArea" name="content" rows="10" placeholder="请输入内容..." minlength="1" required></textarea></div>
                            </div>
                            <div class="am-form-group">
                                <div>
                                    <button type="button" id="save" class="am-btn am-btn-primary">提 交</button>
                                    <button type="button" class="am-btn am-btn-success" onclick="history.go(-1)">返 回</button>
                                </div>
                            </div>
                        </form>
                        </c:if>
                        <c:if test="${empty user}"><span class="blank"><a href="${ctx}/login">登录</a>后可分享</span></c:if>
                    </div>
                </div>
            </div>
            <div class="am-u-sm-4" style="padding: 0px;">
                <div class="am-panel am-panel-default">
                    <div class="title"><span>活跃用户</span></div>
                    <div class="am-panel-bd masterlist">
                        <ul style="padding-left:0;">
                            <c:forEach items="${faq:getAnswersUserTop(10)}" var="userTop" varStatus="status">
                                <li>
                                    <span><img src="<c:choose><c:when test="${empty userTop.photo}">${ctxStatic}/custom/images/user.png</c:when><c:otherwise>${userTop.photo}</c:otherwise></c:choose>" width="54" height="54"></span>
                                    <span>${empty userTop.name?userTop.username:userTop.name}</span>
                                        <%--<a href="#">问问TA</a>--%>
                                    <span class="c1">回答&nbsp;${userTop.size}</span>
                                </li>
                            </c:forEach>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@ include file="footer.jsp" %>
<script type="text/javascript" src="${ctxStatic}/3rd-lib/wangEditor/js/wangEditor.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/custom/js/jq.editor.js"></script>
<script type="text/javascript">
    $(document).ready(function () {

        //初始化编辑器
        $.fn.initEditor('${ctx}','${ctxStatic}','contentArea');

        //提交文章
        $("form#questions").on('click','#save',function(){
            //验证
            if($("#title").val()==''){
                showMsg("问题标题不能为空");
                return;
            }
            if($("#contentArea").val()==''){
                showMsg("问题内容不能为空");
                return;
            }
            var _this = $(this);
            var _form = $("#questions");
            var question = _form.serialize();
            post(_form.attr("action"),question,function(data){
                if(data.ret==1){
                    showMsg("提交成功，请等待系统审核");
                    setTimeout(function(){location.reload();},200);
                }else{
                    showMsg("提交失败");
                }
            });
        });
    });
</script>
</body>
</html>